using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using NCommet.Core;
using log4net;

namespace NCommet.Modules.BRE {
    internal abstract class REInput {
        public bool isValid;
        public bool doGet;
        public ICollection<string> errors;
        public ILog log;

		internal REInput(ILog log) {
			this.errors = new List<string>();
			this.isValid = true;
			this.doGet = false;
            this.log = log;
		}

        protected static bool Contains(NameValueCollection tbl, string Key, string Value)
        {
            string[] values = null;
            if (tbl != null && (values = tbl.GetValues(Key)) != null)
            {
                foreach (string s in values)
                    if (s == Value)
                        return true;
            }
            return false;
        }
    }

    internal class RECanSetRootInput : REInput
    {
        public Item candidateRoot;
        public List<string> tbl;

        internal RECanSetRootInput(Item candidateRoot, ILog log)
            : base(log)
        {
            this.candidateRoot = candidateRoot;
			this.tbl = new List<string>();
        }
    }

	internal class RECanAttachInput : REInput {
		public Item parent;
		public Item candidateChild;
		public NameValueCollection tbl;

		internal RECanAttachInput(Item parent, Item candidateChild, ILog log)
			: base(log) {
			this.parent = parent;
			this.candidateChild = candidateChild;
			this.tbl = new NameValueCollection();
		}

        /// <summary>
        /// Checks if the internal name value collection contains the given key-value pair.
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool Contains(string Key, string Value)
        {
            return Contains(tbl, Key, Value);
        }
	}

    internal class RECanRemoveInput : REInput
    {
        public Item parent;
        public Item child;
        public NameValueCollection tbl;

        internal RECanRemoveInput(Item parent, Item child, ILog log)
            : base(log)
        {
            this.parent = parent;
            this.child = child;
            this.tbl = new NameValueCollection();
        }

        /// <summary>
        /// Checks if the internal name value collection contains the given key-value pair.
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool Contains(string Key, string Value)
        {
            return Contains(tbl, Key, Value);
        }
    }

	internal class RECanContainInput : REInput {
		public Item container;
		public ContentBase content;
		public NameValueCollection tbl;

		internal RECanContainInput(Item container, ContentBase content, ILog log)
			: base(log) {
			this.container = container;
			this.content = content;
			this.tbl = new NameValueCollection();
		}

        /// <summary>
        /// Checks if the internal name value collection contains the given key-value pair.
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool Contains(string Key, string Value)
        {
            return Contains(tbl, Key, Value);
        }
	}
}
